import os
from base.base import BasePage


class AppPage(BasePage):
    page_name = os.path.basename(__file__).split('.')[0]
    app_dev = ("id", "Menu_Code_02")
    create_app = ("xpath", "//button/span[contains(text(), '创建App')]")
    app_name_inp = ("css selector", "input[placeholder='请输入App名称']")
    create_confirm = ("xpath", "//button/span[contains(text(),'确定创建')]")
    alert_text = ("css selector", "div[role='alert']>p")
    name_alert = ("css selector", "div[class='el-form-item__error']")

    def create(self, app_name):
        self.click(self.app_dev)
        self.click(self.create_app)
        self.fill(self.app_name_inp, app_name, "app名字")
        name_alert = self.get_text(self.name_alert, "app输入框")
        if name_alert:
            self.take_screenshot(app_name + "_" + name_alert, self.page_name)
            return name_alert
        self.click(self.create_confirm)
        alert_text = self.get_text(self.alert_text, "确认创建弹窗")
        self.take_screenshot(app_name + "_" + alert_text, self.page_name)
        self.refresh()
        return alert_text

